using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class PoDetailMap : EntityTypeConfiguration<PoDetail>
	{
		public PoDetailMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.ItemCode)
				.HasMaxLength(10);
				
			// Table & Column Mappings
			this.ToTable("PoDetails");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.PoId).HasColumnName("PoId");
			this.Property(t => t.ItemCode).HasColumnName("ItemCode");
			this.Property(t => t.UnitOfMeasurementType).HasColumnName("UnitOfMeasurementType");
			this.Property(t => t.Qty).HasColumnName("Qty");
			this.Property(t => t.SalesPrice).HasColumnName("SalesPrice");
			this.Property(t => t.Discount).HasColumnName("Discount");
			this.Property(t => t.Description).HasColumnName("Description");

			// Relationships
			this.HasOptional(t => t.PoMaster)
				.WithMany(t => t.PoDetails)
				.HasForeignKey(d => d.PoId);
				
		}
	}
}

